/*

Copyright (C) 2009, Etienne Moutot <e.moutot@gmail.com>

This file is part of colorPickerWidget.

    colorPickerWidget is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    colorPickerWidget is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef COLORPICKERWIDGET_H
#define COLORPICKERWIDGET_H

#include <QWidget>
#include <QLabel>
#include <QDoubleSpinBox>

#include "ColorTriangle.h"

class ColorLabel : public QWidget
{
    Q_OBJECT
public:
    ColorLabel(QWidget *parent = 0);
    void setColor(const QColor& color);

signals:
    void dblClick();

protected:
    void paintEvent(QPaintEvent *);
    void mouseReleaseEvent(QMouseEvent *event);

private:
    QColor m_color;
};

class ColorPickerWidget : public QFrame
{
    Q_OBJECT

public:
    ColorPickerWidget(const QString& name = "", QWidget *parent = 0);
    ~ColorPickerWidget();

    QColor getColor() const;
    const QString& getName() const;
    void setName(const QString& name);
    void setTitle(const QString& title);
    void setShowAlpha(bool show = true);

signals:
    void colorChanged(const QColor &color);

public slots:
    void setColor(const QColor &color);

private slots:
    void onColorChanged(const QColor& color);
    void onAlphaChanged(double alpha);

private:
    ColorTriangle *m_colorTriangle;
    ColorLabel *m_colorLabel;
    QColor m_color;
    QString m_name;
    QLabel *m_nameLabel;

    QDoubleSpinBox *m_alpha;
};

#endif // COLORPICKERWIDGET_H
